#include "pipechannel.h"
#include <QCoreApplication>
//静态成员初始化

/**
 *构造函数
 * @brief PipeChannel
 * @param winHeight 窗口高度
 * @param h1 底下管道高度
 * @param x 位置横坐标
 * @param groundHeight 地面高度
 * @param parent
 */
PipeChannel::PipeChannel(int winHeight,int h1, int x, int groundHeight, QObject *parent) : QObject(parent)
{
    this->h1 = h1;
    this->x = x;
    this->groundHeight = groundHeight;
    this->winHeight = winHeight;
    initPipe();
}
/**
 * 初始化管道
 * @brief initPipe
 */
void PipeChannel::initPipe(){
    pipeImage =QImage( QCoreApplication::applicationDirPath().append(R"(/res/pipe.png)"));
    imageMirror = pipeImage.mirrored(false, true);

    pipe1 = QPixmap::fromImage(pipeImage);
    pipe2 = QPixmap::fromImage(imageMirror);
    int h2 = getPiPe2Height();
    pipe1 = pipe1.copy(0, 0, pipe1.width(), h1);
    pipe1 = pipe1.scaled(pipeWidth, h1);

    pipe2 = pipe2.copy(0, pipe2.height()-h2, pipe2.width(), h2);
    pipe2 = pipe2.scaled(pipeWidth, h2);
    isScore = false;
}
/**
 * @brief draw 绘制
 * @param painter 画笔
 */
void PipeChannel::draw(QPainter &painter){
    painter.drawPixmap(x, getY1(), pipe1);
    painter.drawPixmap(x, 0, pipe2);
}
/**
 * @brief setX 设置位置 X坐标
 * @param x
 */
void PipeChannel::setX(int x){
      this->x = x;
}
/**
 * @brief getX 获取位置
 * @return
 */
int PipeChannel::getX(){
    return this->x;
}
/**
 * @brief getY1 获取管道1（底部管道）的y坐标
 * @return
 */
int PipeChannel::getY1(){
    return winHeight - h1 - groundHeight;
}
/**
 * @brief getPiPe2Height 获取管道2的高度
 * @return
 */
int PipeChannel::getPiPe2Height(){
    return winHeight - channelWidth -h1;
}
/**
 * @brief getPipeWidth
 * @return  获取管道宽度
 */
int PipeChannel::getPipeWidth(){
    return this->pipeWidth;
}
/**
 * @brief PipeChannel::setH1
 * @param x
 */
void PipeChannel::setH1(int h1){
    this->h1 = h1;
}
/**
 * @brief PipeChannel::~PipeChannel 析构
 */
PipeChannel::~PipeChannel(){

}

